function RequestHistory(Contract,Duration,BarSize,tws,MidorTrade)%MidorTrade: MIDPOINT for Forex, TRADES for the rest
global tickerID;
EndDate = datestr(now,'yyyymmdd HH:MM:SS');%end dat = ahora
EndDate = strcat(EndDate ,' GMT');

global DataReady HistData 
    HistData.DateStr = cell(2000,1);
    HistData.Open = NaN(2000,1);
    HistData.Close = NaN(2000,1);
    HistData.High = NaN(2000,1);%Added
    HistData.Low = NaN(2000,1);%Added
    HistData.Volume = NaN(2000,1);
    DataReady = 0;

tws.reqHistoricalDataEx(tickerID,Contract,EndDate,Duration,BarSize,MidorTrade,1,1);%MIDPOINT for Forex, TRADES for the rest
tickerID=tickerID+1;
while (DataReady==0)
    pause(0.1); % wait for data to come in
end

